package org.xiaoleng.igateway.configs;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

@Configuration
public class GatewayConfigServiceConfig {

    @Autowired
    private GatewayConfigProperties gatewayConfigProperties;

    @Bean
    public ConfigService buildConfigService() throws NacosException {
        Properties properties = new Properties();
        properties.setProperty(PropertyKeyConst.SERVER_ADDR, gatewayConfigProperties.getServerAddr());
        properties.setProperty(PropertyKeyConst.NAMESPACE, gatewayConfigProperties.getNamespace());
        return NacosFactory.createConfigService(properties);
    }
}
